package com.tledu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tledu.mapper.SectionMapper;
import com.tledu.pojo.Section;
import com.tledu.service.SectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 万秋泊
 * @Date: 2022/5/24 14:15
 * @Description:
 */
@Service
public class SectionServiceImpl extends ServiceImpl<SectionMapper, Section> implements SectionService {
    @Autowired
    private SectionMapper sectionMapper;

    /**
     * 列表查询课程的章节
     *
     * @param course_id 课程id
     * @return
     */
    @Override
    public List<Section> selectCourseSections(Integer course_id) {
        List<Section> sections = sectionMapper.selectCourseSections(course_id);
        //对查询到的结果处理，将错误数据剔除，即：将子章节在父章节的集合中去掉
        for (int i = 0; i < sections.size(); i++) {
            if (sections.get(i).getParent_id() != null) {
                sections.remove(i);
                i--;
            }
        }
        return sections;
    }
}
